import React, {Component} from 'react'
import {StyleSheet, Text, View, Image, TouchableOpacity, ScrollView} from 'react-native'
import actions from "../../../redux/action";
import {connect} from "react-redux";

class CourseNoticeComponent extends Component {
  componentDidMount() {
    const {fetchCourseNotices} = this.props;
    let formData = '';
    let params = {
      studentId: '121',
    };
    for (let i in params){
      formData += encodeURIComponent(i) + '=' + encodeURIComponent(params[i]) + '&'
    }
    console.log(formData)
    fetchCourseNotices(formData)
  }
  courseNotice(){
    let courseNotices = [
      {
        title: '准备开学了'
      },
      {
        title: '剩余课时不多了，现在可以直接在app续费哦！'
      },
    ]
    let courseNotice = <View>
      <View style={MinaStyle.minaTitle}>
        <Text style={MinaStyle.minaTitleLeft}>通知公告</Text>
      </View>
      <View style={styles.courseNotice}>
        {courseNotices.map((item, index) => {
          return (
            <Text ellipsizeMode="tail" numberOfLines={1} key={index}>{item.title}</Text>
          )
        })}
      </View>
    </View>
    return courseNotice;
  }
  render() {
    const {courseNotice} = this.props;
    console.log(courseNotice)
    return (
      this.courseNotice()
    )
  }
}
const mapStateToProps = state => ({
  courseNotice: state.course.courseNotice
});
const mapDispatchToProps = dispatch => ({
  fetchCourseNotices: (params) => dispatch(actions.fetchCourseNotices(params))
});

export default connect(mapStateToProps, mapDispatchToProps)(CourseNoticeComponent);

const styles = StyleSheet.create({
  courseNotice: {
    marginBottom: 30,
  }
})